#!/usr/bin/perl

use Astro::Time;
use strict;

my @months = ( 'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN',
	'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC' );

for (my $i=0;$i<=$#ARGV;$i++) {
	print $ARGV[$i]." is MJD ".&parse_miriad_time($ARGV[$i])."\n";
}

sub parse_miriad_time {
    my $mirtime = shift;

    if ($mirtime =~ /^(..)(...)(..)\:(..)\:(..)\:(....)$/) {
        my $mjd = cal2mjd($3, &arrn(\@months, $2) + 1, 2000 + $1,
                          &hms2time($4, $5, $6));
        return $mjd;
    } else {
        return 0;
    }
}

sub arrn {
    my $a = shift;
    my $b = shift;

    for (my $j=0; $j<=$#{$a}; $j++) {
        if ($a->[$j] eq $b) {
           return $j;
        }
    }
    return -1;
}
